package com.usian.ai.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.usian.ai.common.Result;
import com.usian.ai.common.vo.JobReqVo;
import com.usian.ai.common.vo.PageVo;
import com.usian.ai.mapper.JobMapper;
import com.usian.ai.pojo.Job;
import com.usian.ai.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.function.Function;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 12 06 14 33
 **/

@Service
@Slf4j
public class JobServiceImpl extends ServiceImpl<JobMapper, Job>
implements JobService {

    @Autowired
    JobMapper jobMapper;


    @Override
    public Result listJob(PageVo pageVo) {

       // Page<Job> jobPage =
                //new Page<>(pageVo.getPageNum(), pageVo.getPageSize());
        //Page<Job> jobPage1 = this.baseMapper.selectPage(jobPage, null);

        //连接查询
        //select * from job LEFT JOIN interviewer ON job.interviewer_id = interviewer.id

        PageHelper.startPage(pageVo.getPageNum(), pageVo.getPageSize());
        List<Job> jobs = jobMapper.selectJob();


        log.info("查询结果：{}", jobs);

        PageInfo<Job> jobPageInfo = new PageInfo<>(jobs);

        return Result.ok(jobPageInfo);

    }

    @Override
    public Result addJob(JobReqVo jobReqVo) {
        Job job = new Job();
        job.setCreateTime(new Date());
        job.setUpdatedTime(new Date());

        BeanUtils.copyProperties(jobReqVo,job);

        int insert = this.baseMapper.insert(job);
        return Result.ok(insert);
    }
}
